﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using com.pro2e.console.service.auth.vo;
using com.pro2e.console.generic.util;
using System.Data.SqlClient;
using System.Collections.Generic;
using NHibernate;
using com.pro2e.console.core.valueobject;
using NHibernate.Criterion;


/// <summary>
/// LoginUserDao 的摘要描述
/// </summary>
/// 

namespace com.pro2e.console.service.auth.dao
{
    public class LoginUserDao : DaoImp
    {
        public LoginUserDao()
        {

        }

        public void DaoInsert(LoginUser loginUser)
        {
            loginUser.LastLockoutDate = DateTime.Today;

            loginUser.LastLoginDate = DateTime.Today;

            loginUser.LastPasswordChangedDate = DateTime.Today;

            loginUser.CreateDate = DateTime.Now;

            loginUser.FailedPasswordAttemptWindowStart = DateTime.Today;

            loginUser.FailedPasswordAnswerAttemptWindowStart = DateTime.Today;

            base.DaoInsert(loginUser);
           
        }


        public void DaoUpdate(LoginUser loginUser)
        {
            CheckVersion(loginUser,loginUser.UserId);
            base.DaoUpdate(loginUser);
        }
 
  

        public LoginUser GetVOByEmail(string email)
        {

            ICriteria criteria = GetHBNSession().CreateCriteria(typeof(LoginUser));
            criteria.Add(Expression.Eq("Email", email));

            object result = criteria.List();

            if (result != null)
            {
                return (LoginUser)result;
            }
            else
            {
                return null;
            }

        }
    }
}

